//
//  KLAccountView.m
//  KLShoppingList
//
//  Created by apple on 2017/8/23.
//  Copyright © 2017年 NetEaseExam. All rights reserved.
//

#import "KLAccountView.h"

@interface KLAccountView ()
@property (weak, nonatomic) IBOutlet UIButton *selectedBtn;
@property (weak, nonatomic) IBOutlet UILabel *totalPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalTaxLabel;
@property (weak, nonatomic) IBOutlet UIButton *totalCountBtn;

@end

@implementation KLAccountView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (instancetype)totalAccountView{
    KLAccountView *view = [[[NSBundle mainBundle] loadNibNamed:@"KLAccountView" owner:nil options:nil] firstObject];
    
    return view;
}

- (void)setTotalCount:(NSUInteger)totalCount{
    _totalCount = totalCount;
    NSString *title = [NSString stringWithFormat:@"结算(%lu)",(unsigned long)totalCount];
    [self.totalCountBtn setTitle:title forState:UIControlStateNormal];
}

- (void)setTotalPrice:(CGFloat)totalPrice{
    _totalPrice = totalPrice;
    NSString *priceStr = [NSString stringWithFormat:@"￥%.2f",totalPrice];
    self.totalPriceLabel.text = priceStr;
}

- (void)setTotalTax:(CGFloat)totalTax{
    _totalTax = totalTax;
    NSString *taxStr = [NSString stringWithFormat:@"含税费￥%.2f，不含运费",totalTax];
    self.totalTaxLabel.text = taxStr;
}

- (void)setAllGoodsIsChoosed:(BOOL)allGoodsIsChoosed{
    _allGoodsIsChoosed = allGoodsIsChoosed;
    self.selectedBtn.selected = allGoodsIsChoosed;
}

- (IBAction)allGoodsSelectedBtnClicked:(UIButton *)sender {
    sender.selected = !sender.selected;
    
    if (sender.selected == YES) {
        NSLog(@"全选了goods");
    }else{
        NSLog(@"取消全选了goods");
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(allGoodsSelected:isSelected:)]) {
        [self.delegate allGoodsSelected:self isSelected:sender.selected];
    }
}

- (IBAction)settleAccountsBtnClicked:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(settleAccounts:)]) {
        [self.delegate settleAccounts:self];
    }
}

@end
